/**
 * @param {number} n
 * @return {number}
 */
 var nextBeautifulNumber = function(n) {
  const check = (x) => {
      const arr = String(x).split('')
      const map = new Map()
      for(const ch of arr){
          const x = Number(ch)
          map.set(x, (map.get(x) || 0) + 1)
      }
      for(const [x, cnt] of map.entries()){
          if(x !== cnt) return false
      }
      return true
  }
  let ans = n+1
  while(true){
      if(check(ans)) return ans
      ans++
  }
};